package stmlib;
import java.util.*;

/** 
 *  A transactional java.util.ListIterator.
 *  Can share a lock with the underlying Sequence(List).
 */
public class StmListIterator<E> extends Lockable implements ListIterator<E> {
    ListIterator<E> lsti;
    public StmListIterator(ListIterator<E> source, LockManager lm) {this.lm=lm; this.lsti=source;}
    public boolean hasNext() { lm.readLock(); return lsti.hasNext(); }
    public E next() { lm.readLock(); return lsti.next(); }
    public void remove() { lm.writeLock(); lsti.remove(); }
    public boolean hasPrevious() { lm.readLock(); return lsti.hasPrevious(); }
    public E previous() { lm.readLock(); return lsti.previous(); }
    public void add(E e) { lm.writeLock(); lsti.add(e); }
    public void set(E e) { lm.writeLock(); lsti.set(e); }
    public int previousIndex() { lm.readLock(); return lsti.previousIndex(); }
    public int nextIndex() { lm.readLock(); return lsti.nextIndex(); }
    public StmListIterator<E> lock() { lm.writeLock(); return this; }
}


